layui.use(['element','form','jquery','layer','laydate','upload'], function() {
    var element = layui.element;
    var form = layui.form;
    var $ = layui.jquery;
    var layer = layui.layer;
    var laydate = layui.laydate;
    var upload = layui.upload;

    laydate.render({
        elem: "#startDate",
        type: "datetime",
        trigger: "click"
    });
    laydate.render({
        elem: "#expireDate",
        type: "datetime",
        trigger: "click"
    });

    var a = localStorage.getItem('createId');
    var createId = $('#createId').val(a);

    /* 上传图片开始 */
    var uploadInst = upload.render({
        elem: "#test",
        url: "/upload/uploadFile",
        multiple: true,
        size:2248,
        field: "files",
        accept: "images",
        before: function (obj) {
            $('#images').show();
        },
        done: function (res, index, upload) {
            var imgAddress = res.data.path;
            $('#image').html('<img src="' + imgAddress
                + '" height="100px" width="100px" border="1px solid #ccc" class="layui-upload-img uploadImgPreView">');
            $('input[name=imgAddress]').val(imgAddress);
        },
        error: function () {
            //演示失败状态，并实现重传
            var demoText = $('#demoText');
            demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
            demoText.find('.demo-reload').on('click', function () {
                uploadInst.upload();
            });
        }, progress: function (n, elem, e) {
            element.progress('demo', n + '%');
            if (n == 100) {
                layer.msg('上传完毕', {icon: 1});
            }
        }
    });
    /* 上传图片结束 */

    /* 添加轮播图 */
    form.on('submit(sub)', function(data){
        $.ajax({
            url:'/banner/addBanner',
            data:data.field,
            type:'post',
            dataType:'json',
            success:function(data){
               layer.msg("添加成功");
            }
        });
        return false;
    });
    //刷新
    Refresh = function Refresh() {
        location.reload();
    }
    //返回
    goBack= function goBack() {
        parent.$('#beforeHref').val($('.layui-elem-quote').children('span').eq(0).text());
        parent.before();
        return false;
    }
});